/**
 * zmn员工模块-不限IP日期编辑
 * 文件命名格式：zmn.模块.表/功能.js
 * @author heguanghua
 * @since 2020/05/10 18:10
 */
layui.define(['form', 'zmnApp', 'laydate'], function (exports) {
    let $ = layui.$;
    let form = layui.form;
    let layer = layui.layer;
    let laydate = layui.laydate;
    let zmnApp = layui.zmnApp;

    form.render(null, "zmn-form");

    let dateRange = null;
    //日期
    laydate.render({
        elem: "#dateRange",
        type: "datetime",
        range: true,
        format: 'yyyy/MM/dd HH:mm:ss',
        zIndex: 99999999,
        value: dateRange,
        done: function (value, startDate, endDate) { //监听日期被切换
            var hours = endDate.hours;
            var minutes = endDate.minutes;
            var seconds = endDate.seconds;
            if (hours == "0" && minutes == "0" && seconds == "0"){
                $(".layui-laydate-footer [lay-type='datetime'].laydate-btns-time").click();
                // 改变结束时间为23:59:59
                $(".laydate-main-list-1 .layui-laydate-content li ol li:last-child").click();
                $(".layui-laydate-footer [lay-type='date'].laydate-btns-time").click();
            }
        }
    });

    // 获取弹出窗口索引
    var index = parent.layer.getFrameIndex(window.name);

    //查询条件重置
    form.on('submit(zmn-form-reset)', function (obj) {
        form.val("zmn-form", {
            "dateRange": ""
        });
        return false;
    });

    // 提交
    form.on('submit(zmn-form-submit)', function (obj) {
        let data = obj.field;
        let url = zmnApp.SYS_BASE_URL + "/staff/modify/setOpenDate.action";
        let jumpStop = false;
        $.ajax({
            async: false,
            type: "POST", url: url,
            dataType: "json", data: data,
            success: function (json) {
                layer.msg(json.message);
                if (json.status == 200) {
                    setTimeout(function () {
                        parent.layer.close(index)
                    }, 1500);
                }
                return;
            },
            error: function (XMLHttpRequest, tstaffStatus, errorThrown) {
            }
        })
        return false;
    });

    //对外暴露的接口
    exports('staff_detail_opendate', {});
});